package com.ww.springboot.mybatis.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.ww.springboot.mybatis.data.service.IOnlineChannelServiceBindService;
import com.ww.springboot.mybatis.dto.CustomizePage;
import com.ww.springboot.mybatis.dto.OnlineChannelServiceBindDTO;
import com.ww.springboot.mybatis.dto.OnlineChannelServiceBindFindDTO;
import com.ww.springboot.mybatis.po.OnlineChannelServiceBindPO;
import com.ww.springboot.mybatis.vo.OnlineChannelServiceBindVO;
import lombok.AllArgsConstructor;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 控制器
 *
 * @author Chill
 */
@RestController
@AllArgsConstructor
@RequestMapping("/onlineChannelServiceBind")
public class OnlineChannelServiceBindController {

    private final IOnlineChannelServiceBindService onlineChannelServiceBindService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<OnlineChannelServiceBindPO> detail(@RequestParam Long id) {
        List<OnlineChannelServiceBindPO> pos = onlineChannelServiceBindService.selectAllList(id);
        return R.ok(pos.get(0));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R<Boolean> update(@Valid @RequestBody OnlineChannelServiceBindDTO bindDTO) {
        boolean flag = onlineChannelServiceBindService.updateById(bindDTO);
        return R.ok(flag);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R<Boolean> save(@Validated(OnlineChannelServiceBindDTO.Save.class) @RequestBody OnlineChannelServiceBindDTO bindDTO) {
        boolean flag = onlineChannelServiceBindService.save(bindDTO);
        return R.ok(flag);
    }

    /**
     * 删除
     *
     * @param ids 主表id 多个用“,”分割
     * @return
     */
    @PostMapping("/remove")
    public R<Boolean> remove(@RequestParam String ids) {
        return R.ok(onlineChannelServiceBindService.deleteAll(ids));
    }

    @PostMapping("/test")
    public R<String> test(@RequestBody OnlineChannelServiceBindFindDTO findDTO) {
        List<Long> bindList = onlineChannelServiceBindService.getChannelId(findDTO);
        return R.ok(bindList.toString());
    }


}
